package com.blic.service;

import java.util.UUID;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import com.blic.exception.ExceptionUtil;

/**
 * 抽象Service
 * 
 * @author blic team
 *
 */
public abstract class AbstractService implements ApplicationContextAware {

	/** 日志类 */
	protected final Logger logger = LoggerFactory.getLogger(super.getClass());
	/** Spring 容器 */
	protected ApplicationContext ctx;
	
	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		this.ctx = applicationContext;
	}

	/**
	 * 获得唯一的UUID
	 * 
	 * @return String
	 */
	protected String getUuid() {
		return UUID.randomUUID().toString().replaceAll("-", "");
	}

	/**
	 * 获取异常的堆栈信息
	 * 
	 * @param t
	 * @return
	 */
	protected String getStackTrace(Throwable t) {
		return ExceptionUtil.getStackTrace(t);
	}

}
